package com.huike.clues.service.impl;


import com.huike.clues.domain.dto.RecordDto;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.StringUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Resource
    private TbClueTrackRecordMapper clueTrackRecordMapper;

    /**
     * 新增线索跟进记录表
     *
     * @param recordDto
     * @return
     */
    @Override
    public String add(RecordDto recordDto) {
        if (StringUtils.isEmpty(recordDto.getRecord()) || StringUtils.isEmpty(recordDto.getSubject())
                || StringUtils.isEmpty(recordDto.getLevel()) || recordDto.getNextTime() == null) {
            return "操作失败";
        }
        String username = SecurityUtils.getUsername();
        recordDto.setCreateBy(username);
        recordDto.setType("1");
        recordDto.setCreateTime(DateUtils.getNowDate());
        clueTrackRecordMapper.add(recordDto);
        return "操作成功";
    }

    @Override
    public TableDataInfo list(Long clueId) {
        TableDataInfo tableDataInfo = new TableDataInfo();
        List<ClueTrackRecordVo> select = clueTrackRecordMapper.select(clueId);

        tableDataInfo.setTotal(select.size());
        tableDataInfo.setRows(select);
        tableDataInfo.setMsg("查询成功");
        tableDataInfo.setCode(200);
        return tableDataInfo;
    }
}
